// Assume we want to use a pool of numThread threads. fork out numThread threads, and then each one that returns will start checking primality of testedNumber+numThread. For 5 threads, start 1-5. When 1 completes, it begins 1+5=6.
package nachos.threads;

class PrimePool implements Runnable
{
	public PrimePool()
	{
		NUMTHREADS = 5;
		exit = false;
		count = new int[1];
		count[0] = 0;
		lower = 1;
		upper = 6;
	}

	public void run()
	{
		while(!exit)
		{
			if (count[0] < NUMTHREADS)
			{
				(new KThread(new DeterPrime(lower, upper, count))).fork();
				lower = lower + 5;
				upper = upper + 5;
			}
			
			if(lower > 100)
			{
				exit = true;
				System.out.println("Done determining prime numbers.");
			}
		}
	}
	
	private int NUMTHREADS;
	private boolean exit;
	private int[] count;  //must be an array so that we can pass by reference
	private int lower;
	private int upper;
}
